//
//  TPBTabBarController.m
//  EncryptionTPB
//
//  Created by 吕剑锋 on 15/9/14.
//  Copyright © 2015年 coderjianfeng. All rights reserved.
//

#import "TPBTabBarController.h"
#import "TPBTabBar.h"

@interface TPBTabBarController ()

@end

@implementation TPBTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIViewController *c1 = [[UIViewController alloc] init];
    c1.view.backgroundColor = [UIColor redColor];
    
    UIViewController *c2 = [[UIViewController alloc] init];
    c2.view.backgroundColor = [UIColor greenColor];
    
    self.viewControllers = @[c1, c2];
    
    [self.tabBar removeFromSuperview];
    
    TPBTabBar *customTabBar = [[TPBTabBar alloc] initWithFrame:self.tabBar.frame];
    customTabBar.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:customTabBar];
    
    for (int i = 0; i < self.viewControllers.count; i++) {
        //UIButton *btn = [[UIButton alloc] init];
        UIButton *btn = [[UIButton alloc] init];
        
//        NSString *imageName = [NSString stringWithFormat:@"TabBar%d", i + 1];
//        NSString *imageNameSel = [NSString stringWithFormat:@"TabBar%dSel", i + 1];
//        
//        [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
//        [btn setImage:[UIImage imageNamed:imageNameSel] forState:UIControlStateSelected];
        [btn setImage:[UIImage imageNamed:@"call"] forState:UIControlStateNormal];
        
        CGFloat x = i * customTabBar.frame.size.width / 2;
        btn.frame = CGRectMake(x, 0, customTabBar.frame.size.width / 2, customTabBar.frame.size.height);
        
        [customTabBar addSubview:btn];
        
        btn.tag = i;//设置按钮的标记, 方便来索引当前的按钮,并跳转到相应的视图
        
        //带参数的监听方法记得加"冒号"
        [btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
        
        //设置刚进入时,第一个按钮为选中状态
//        if (0 == i) {
//            btn.selected = YES;
//            self.selectedBtn = btn;  //设置该按钮为选中的按钮
//        }  
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
